/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.chlitina.store.modules.employee.service;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.chlitina.store.common.persistence.Page;
import com.chlitina.store.common.service.BaseService;
import com.chlitina.store.modules.employee.dao.StoreEmployeeLeftCommentDao;
import com.chlitina.store.modules.employee.entity.StoreEmployeeLeftComment;
import com.chlitina.store.modules.sys.utils.StoreUtils;

/**
 * 离职员工评价Service
 * @author liujiang
 * @version 2013-11-12
 */
@Component
@Transactional(readOnly = true)
public class StoreEmployeeLeftCommentService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(StoreEmployeeLeftCommentService.class);
	
	@Autowired
	private StoreEmployeeLeftCommentDao storeEmployeeLeftCommentDao;
	
	public StoreEmployeeLeftComment get(Long id) {
		return storeEmployeeLeftCommentDao.findOne(id);
	}
	
	public Page<StoreEmployeeLeftComment> find(Page<StoreEmployeeLeftComment> page, 
			String searchName, Integer status) {
		DetachedCriteria dc = storeEmployeeLeftCommentDao.createDetachedCriteria();
		if (StringUtils.isNotEmpty(searchName)){
			dc.createAlias("employee", "e");
			if(status == null || status  == 0) {
				dc.add(Restrictions.like("e.sfzh", "%"+ searchName +"%"));
			} else if(status == 1) {
				dc.add(Restrictions.like("e.name", "%"+ searchName +"%"));
			} else {
				dc.add(Restrictions.like("e.mobile", "%"+ searchName +"%"));
			}
		}
		dc.addOrder(Order.desc("id"));
		return storeEmployeeLeftCommentDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(StoreEmployeeLeftComment storeEmployeeLeftComment) {
		storeEmployeeLeftCommentDao.save(storeEmployeeLeftComment);
	}
	
	@Transactional(readOnly = false)
	public void delete(Long id) {
		storeEmployeeLeftCommentDao.delete(id);
	}
	
}
